<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-card>
        <el-tabs>
          <el-tab-pane label="登录账户设置">
            <!-- 放置表单 -->
            <el-form
              ref="form"
              label-width="120px"
              :model="formData"
              :rules="formRules"
              style="margin-left: 120px; margin-top: 30px"
            >
              <el-form-item label="姓名:" prop="username">
                <el-input v-model="formData.username" style="width: 300px" />
              </el-form-item>
              <el-form-item label="密码:">
                <el-input
                  v-model="formData.password2"
                  style="width: 300px"
                  type="password"
                  show-password
                />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="submit">更新</el-button>
              </el-form-item>
            </el-form>
          </el-tab-pane>
          <el-tab-pane label="个人详情">
            <user-info />
          </el-tab-pane>
          <el-tab-pane label="岗位信息">
            <job-info />
          </el-tab-pane>
        </el-tabs>
      </el-card>
    </div>
  </div>
</template>
<script>
import userInfo from './components/user-info.vue'
import jobInfo from './components/job-info.vue'
import { getEmployeeInfo, editEmployeeInfo } from '@/api/employees'
export default {
  name: 'Details',
  components: {
    userInfo,
    jobInfo
  },
  data() {
    return {
      formData: {},
      formRules: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.initData()
  },
  methods: {
    async initData() {
      const res = await getEmployeeInfo(this.$route.params.id)
      this.formData = res
    },
    async submit() {
      await this.$refs.form.validate()
      await editEmployeeInfo({
        ...this.formData,
        // password: this.formData.password2 || this.formData.password
        password: this.formData.password2 ? this.formData.password : ''
      })
      this.$message.success('更新成功')
    }
  }
}
</script>
<style></style>
